package com.example.sunsg.okhttptest.rxjava;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import com.breadtrip.R;
import com.example.sunsg.okhttptest.bean.Image;
import com.example.sunsg.okhttptest.greendao.bean.Customer;
import com.example.sunsg.okhttptest.greendao.bean.Student;
import com.example.sunsg.okhttptest.retrofit.Ilogin;
import com.example.sunsg.okhttptest.retrofit.OkHttp3ClientManager;
import com.example.sunsg.okhttptest.retrofit.Token;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;

import org.reactivestreams.Publisher;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.FlowableEmitter;
import io.reactivex.FlowableOnSubscribe;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.Observer;
import rx.Scheduler;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;


public class RxJavaActivity extends AppCompatActivity {
    private ImageView imageView;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private GoogleApiClient client;

    public static void launch(Context context) {
        Intent intent = new Intent(context, RxJavaActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rx_java);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        init();
        rxjava();
        loadImageview();
        loadimageViewFormResIds();
        rxjava2timers();
        getToken();
        rxjava2_0();
        testAtomicboolean();
    }

    private void init() {
        imageView = (ImageView) findViewById(R.id.imview);
    }

    private void rxjava() {
        Observer<String> observer = new Observer<String>() {
            @Override
            public void onCompleted() {
                Log.i("test", "observer oncomplte");
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(String s) {
                Log.i("test", "s = " + s);
            }
        };

        Subscriber<String> subscriber = new Subscriber<String>() {

            @Override
            public void onStart() {
                super.onStart();
                //在订阅发生的线程中调用
                Log.i("test", "onstart");
            }

            @Override
            public void onCompleted() {
                Log.i("test", "subscriber onCompleted");
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(String s) {
                Log.i("test", "subscriber  s = " + s);
            }

        };

        Observable observable = Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                subscriber.onStart();
                subscriber.onNext("hello");
                subscriber.onNext("world");
                subscriber.onCompleted();
            }
        });

        Action1<String> onNextAction1 = new Action1<String>() {
            @Override
            public void call(String s) {
                Log.i("test", "onNextAction1 = " + s);
            }
        };

        Action1<Throwable> onErroeAction = new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                Log.i("test", "onerrroaction " + throwable.toString());
            }
        };

        Action0 oncomplteAction = new Action0() {
            @Override
            public void call() {
                Log.i("test", "oncomplteAction");
            }
        };

        String[] arrays = new String[]{"dfs", "dsfsdf", "sdfsdf", "sdfsdf", "sdf"};

        observable = Observable.from(arrays);
        observable.subscribe(observer);
        observable.subscribe(subscriber);
//        observable.subscribe(onNextAction1);
//        observable.subscribe(onNextAction1,onErroeAction);
        observable.subscribe(onNextAction1, onErroeAction, oncomplteAction);

    }

    private void loadImageview() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Subscription subscribe = null;
                subscribe = Observable.create(new Observable.OnSubscribe<Drawable>() {
                    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                    @Override
                    public void call(Subscriber<? super Drawable> subscriber) {
                        Drawable drawable = getDrawable(R.drawable.ic_menu_camera);
                        subscriber.onNext(drawable);
                        subscriber.onCompleted();
                        Log.i("test", "Thread.currentThread().getName() =call" + Thread.currentThread().getName());
//                        while (true){
//                            Log.i("test","whileedd");
//                            try {
//                                Thread.sleep(10);
//                            } catch (InterruptedException e) {
//                                e.printStackTrace();
//                            }
//                        }
                    }
                }).subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Subscriber<Drawable>() {
                            @Override
                            public void onCompleted() {

                            }

                            @Override
                            public void onError(Throwable e) {

                            }

                            @Override
                            public void onNext(Drawable drawable) {
                                Log.i("test", "Thread.currentThread().getName() =" + Thread.currentThread().getName());
//                                imageView.setImageDrawable(drawable);

                            }
                        });
            }
        }).start();


    }

    private void loadImageViewFormResId() {
        Observable.just(R.drawable.im_life_btn_done_pressed)
                .subscribeOn(Schedulers.io())
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
                        Log.i("test", "ddddddddThread.currentThread().getName() Integer=" + Thread.currentThread().getName());
                        Log.i("test", "start");

                    }
                })
                .subscribeOn(Schedulers.newThread())
                .observeOn(Schedulers.newThread())
                .map(new Func1<Integer, Bitmap>() {
                    @Override
                    public Bitmap call(Integer integer) {
                        Log.i("test", "Thread.currentThread().getName() Integer=" + Thread.currentThread().getName());
                        return BitmapFactory.decodeResource(getResources(), integer);
                    }
                })
                .observeOn(Schedulers.io())
                .map(new Func1<Bitmap, Drawable>() {
                    @Override
                    public Drawable call(Bitmap bitmap) {
                        Log.i("test", "Thread.currentThread().getName() Bitmap=" + Thread.currentThread().getName());
                        return new BitmapDrawable(bitmap);
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<Drawable>() {
                    @Override
                    public void call(Drawable drawable) {
                        if (drawable != null) {
                            Log.i("test", "Thread.currentThread().getName() drawable=" + Thread.currentThread().getName());
//                                imageView.setImageDrawable(drawable);
                        }
                    }
                });
    }

    private void loadimageViewFormResIds() {
//        Student[] stud = new Student[1];
        final Student stu = new Student();
        stu.setAge("20");
        stu.setName("sunsg");
        Course course = new Course("语文", "小李");
        Course course1 = new Course("英语", "小陈");
        List<Course> courses = new ArrayList<>();
        courses.add(course);
        courses.add(course1);
        stu.setCourse(courses);
//        stud[0] = stu;
        Observable.just(stu).flatMap(new Func1<Student, Observable<Course>>() {
            @Override
            public Observable<Course> call(Student student) {
                return Observable.from(student.getCourse());
            }
        }).doOnNext(new Action1<Course>() {
            @Override
            public void call(Course course) {

            }
        }).subscribe(new Action1<Course>() {
            @Override
            public void call(Course course) {
                Log.i("test", course.toString());
            }
        });
    }

    public static class Student {
        private String name;
        private String age;
        private List<Course> course;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }

        public List<Course> getCourse() {
            return course;
        }

        public void setCourse(List<Course> course) {
            this.course = course;
        }

        @Override
        public String toString() {
            return "name = " + name + " age = " + age;
        }
    }

    public static class Course {
        private String name;
        private String teacher;

        public Course(String name, String teacher) {
            this.name = name;
            this.teacher = teacher;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getTeacher() {
            return teacher;
        }

        public void setTeacher(String teacher) {
            this.teacher = teacher;
        }

        @Override
        public String toString() {
            return "name = " + name + " teacher = " + teacher;
        }
    }

    Subscription subscription = null;

    private void rxjava2timers() {
        Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                String ss = "11";
                String ss2 = "22";
                subscriber.onNext(ss);
                subscriber.onNext(ss2);
                subscriber.onCompleted();
            }
        }).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                Log.i("test", " s = " + s);
            }
        });
        Observable.just("11", "22", "33")
                .subscribe(new Action1<String>() {
                    @Override
                    public void call(String s) {
                        Log.i("test", " s = " + s);
                    }
                });
        subscription = Observable.create(new Observable.OnSubscribe<Integer>() {
            @Override
            public void call(Subscriber<? super Integer> subscriber) {
                Log.i("test", "Observable.OnSubscribe rxjavajjjjjjjjjjjjjjjjjjjjjjjj threadname = " + Thread.currentThread().getName());
                subscriber.onNext(R.drawable.beauty);
                subscriber.onCompleted();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Action1<Integer>() {
                    @Override
                    public void call(Integer integer) {
                        Log.i("test", "do no next");
                        Log.i("test", "doOnNext rxjavajjjjjjjjjjjjjjjjjjjjjjjj threadname = " + Thread.currentThread().getName());
                        imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), integer));
                    }
                })
                .observeOn(Schedulers.io())
                .map(new Func1<Integer, Bitmap>() {
                    @Override
                    public Bitmap call(Integer integer) {
                        Log.i("test", "map");
                        Log.i("test", "map rxjavajjjjjjjjjjjjjjjjjjjjjjjj threadname = " + Thread.currentThread().getName());
                        return BitmapFactory.decodeResource(getResources(), integer);
                    }
                })
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Bitmap>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(Bitmap bitmap) {
                        Log.i("test", "subscribe");
                        Log.i("test", "onNext rxjavajjjjjjjjjjjjjjjjjjjjjjjj threadname = " + Thread.currentThread().getName());
//                        imageView.setImageBitmap(bitmap);
                        subscription.unsubscribe();
                    }
                });

//                .subscribe(new Action1<Bitmap>() {
//                    @Override
//                    public void call(Bitmap bitmap) {
//                        Log.i("test","subscribe");
//                        imageView.setImageBitmap(bitmap);
//                    }
//                });
    }


    /***
     * get 请求
     */
    private void getToken() {
        Retrofit retrofit = new Retrofit.Builder()
                .client(OkHttp3ClientManager.mOkHttpClient)
                .baseUrl("http://api.breadtrip.com/android/bdchannel/")
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create()).build();
//        Ilogin login = retrofit.create(Ilogin.class);
//        Call<Token> call = login.getAccessToken();
//        call.enqueue(new Callback<Token>() {
//            @Override
//            public void onResponse(Call<Token> call, Response<Token> response) {
//                Token token = response.body();
////                OkHttp3ClientManager.token = "Bearer "+token.getAccess_token();
////                login();
//                loadImageViewFormResId();
//            }
//
//            @Override
//            public void onFailure(Call<Token> call, Throwable t) {
//
//            }
//        });
        Ilogin login = retrofit.create(Ilogin.class);
        login.getAccessTokenObservece().doOnNext(new Action1<Token>() {
            @Override
            public void call(Token token) {
                Log.i("test", "tokennnnnnnnnnnnnnnnnnnnnnnnnnn  doOn next" + " thread name = " + Thread.currentThread().getName());
            }
        }).subscribeOn(Schedulers.io()).map(new Func1<Token, String>() {
            @Override
            public String call(Token token) {
                Log.i("test", "tokennnnnnnnnnnnnnnnnnnnnnnnnnn  map" + " thread name = " + Thread.currentThread().getName());
                return token.getAccess_token();
            }
        }).subscribe(new Subscriber<String>() {
            @Override
            public void onCompleted() {
                Log.i("test", "tokennnnnnnnnnnnnnnnnnnnnnnnnnn  onCompleted" + " thread name = " + Thread.currentThread().getName());
            }

            @Override
            public void onError(Throwable e) {
                Log.i("test", "tokennnnnnnnnnnnnnnnnnnnnnnnnnn  onError" + " thread name = " + Thread.currentThread().getName());
            }

            @Override
            public void onNext(String s) {
                Log.i("test", "tokennnnnnnnnnnnnnnnnnnnnnnnnnn  subscribe" + " thread name = " + Thread.currentThread().getName() + "s = " + s);
            }
        });
    }


    @Override
    public void onStart() {
        super.onStart();

    }

    @Override
    public void onStop() {
        super.onStop();
    }


    //=========================================rxjava 2.0=========================================================================
    private CompositeDisposable mCompositeDisposablel = new CompositeDisposable();

    private void rxjava2_0() {
        //简单使用
        io.reactivex.Observable<String> observable = io.reactivex.Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("ssss");
                e.onNext("ddddd");
                e.onComplete();

            }
        });

        io.reactivex.Observer<String> observer = new io.reactivex.Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                Log.i("test2", "Disposable");
//                d.dispose();
                mCompositeDisposablel.add(d);
            }

            @Override
            public void onNext(String s) {
                Log.i("test2", "onNext s = " + s);
            }

            @Override
            public void onError(Throwable e) {
                Log.i("test2", "onError e = " + e.toString());
            }

            @Override
            public void onComplete() {
                Log.i("test2", "onComplete ");
            }
        };

        //1
//        observable.subscribe(observer);

        //2
        io.reactivex.Observable<String> observable1 = io.reactivex.Observable.just("guang");
//        observable1.subscribe(observer);

        //3
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            list.add("Hello" + i);
        }
        io.reactivex.Observable<String> observable2 = io.reactivex.Observable.fromIterable(list);
//        observable2.subscribe(observer);

        //4
        io.reactivex.Observable<String> observable3 = io.reactivex.Observable.defer(new Callable<ObservableSource<? extends String>>() {
            @Override
            public ObservableSource<? extends String> call() throws Exception {
                return io.reactivex.Observable.just("jdlfjd", "dkjflsdjf", "jdlfj");
            }
        });
//        observable3.subscribe(observer);
        //5
        io.reactivex.Observable<Long> observable4 = io.reactivex.Observable.interval(2, TimeUnit.SECONDS);
//        observable4.subscribe(new io.reactivex.Observer<Long>() {
//            @Override
//            public void onSubscribe(Disposable d) {
//                Log.i("test2","interval Disposable");
//                mCompositeDisposablel.add(d);
//            }
//
//            @Override
//            public void onNext(Long aLong) {
//                Log.i("test2","interval onNext along = "+aLong);
//            }
//
//            @Override
//            public void onError(Throwable e) {
//                Log.i("test2","interval e.tostribng "+e.toString());
//            }
//
//            @Override
//            public void onComplete() {
//                Log.i("test2","onComplete");
//            }
//        });

        //6
//        mCompositeDisposablel.add(io.reactivex.Observable.interval(2,TimeUnit.SECONDS).subscribe(new Consumer<Long>() {
//            @Override
//            public void accept(Long aLong) throws Exception {
//                Log.i("test2","interval onNext along = "+aLong);
//            }
//        }));

        //7
//        mCompositeDisposablel.add(io.reactivex.Observable.range(1,30).subscribe(new Consumer<Integer>() {
//            @Override
//            public void accept(Integer integer) throws Exception {
//                Log.i("test2","range onNext along = "+integer);
//            }
//        }));

        //8
//        mCompositeDisposablel.add(io.reactivex.Observable.timer(2,TimeUnit.SECONDS).subscribe(new Consumer<Long>() {
//            @Override
//            public void accept(Long aLong) throws Exception {
//                Log.i("test2","timer onNext along = "+aLong);
//            }
//        }));

        //9
//        io.reactivex.Observable<String> observable5 = io.reactivex.Observable.just("ddd").repeat(20);
//        observable5.subscribe(observer);

        //10
//        mCompositeDisposablel.add(io.reactivex.Observable.just("djkf","djkfl").map(new Function<String, Integer>() {
//            @Override
//            public Integer apply(String s) throws Exception {
//                return s.length();
//            }
//        }).subscribe(new Consumer<Integer>() {
//            @Override
//            public void accept(Integer integer) throws Exception {
//                Log.i("test2","map onNext integer = "+integer);
//            }
//        }));
        //11
        List<Student> stus = getStudents();
//        mCompositeDisposablel.add(io.reactivex.Observable.fromIterable(stus).flatMap(new Function<Student, ObservableSource<Course>>() {
//            @Override
//            public ObservableSource<Course> apply(Student student) throws Exception {
//                Log.i("test2","student = "+student.toString());
//                return io.reactivex.Observable.fromIterable(student.getCourse());
//            }
//        }).subscribe(new Consumer<Course>() {
//            @Override
//            public void accept(Course course) throws Exception {
//                Log.i("test2","course = "+course.toString());
//            }
//        }));
        //12
        mCompositeDisposablel.add(Flowable.fromIterable(stus).filter(new Predicate<Student>() {
            @Override
            public boolean test(Student student) throws Exception {
//                Log.i("test2","test student = "+student.toString());
//                if(student.name.equals("sunsg susng")){
//                    return true;
//                }
                return true;
            }
        }).take(1).flatMap(new Function<Student, Publisher<Course>>() {
            @Override
            public Publisher<Course> apply(Student student) throws Exception {
                Log.i("test2", "student = " + student.toString());
                return Flowable.fromIterable(student.getCourse());
            }
        }).doOnNext(new Consumer<Course>() {
            @Override
            public void accept(Course course) throws Exception {
                Log.i("test2", "doOnNext = " + course.toString());
            }
        }).filter(new Predicate<Course>() {
            @Override
            public boolean test(Course course) throws Exception {
//                Log.i("test2","test course = "+course.toString());
//                if(course.getName().equals("语文2")){
//                    return true;
//                }
                return true;
            }
        }).subscribe(new Consumer<Course>() {
            @Override
            public void accept(Course course) throws Exception {
                Log.i("test2", "course = " + course.toString());
            }
        }));

        rxjava2_0_1();
    }

    private void rxjava2_0_1() {
        io.reactivex.Flowable<String> observable = io.reactivex.Flowable.just("guang");
        observable.subscribe(new org.reactivestreams.Subscriber<String>() {
            @Override
            public void onSubscribe(org.reactivestreams.Subscription s) {

            }

            @Override
            public void onNext(String s) {

            }

            @Override
            public void onError(Throwable t) {

            }

            @Override
            public void onComplete() {

            }
        });
//
//        io.reactivex.Observable.create(new ObservableOnSubscribe<Integer>() {
//            @Override
//            public void subscribe(ObservableEmitter<Integer> e) throws Exception {
//                Log.d("test2", "subscribeOn所在的线程：" + Thread.currentThread().getName());
//                Log.d("test2", "subscribeOn 发送的数据:" + "1");
//                e.onNext(1);
//            }
//        }).subscribeOn(io.reactivex.schedulers.Schedulers.io()).observeOn(io.reactivex.android.schedulers.AndroidSchedulers.mainThread())
//                .subscribe(new Consumer<Integer>() {
//                    @Override
//                    public void accept(Integer integer) throws Exception {
//                        Log.d("test", "observeOn 所在的线程：" + Thread.currentThread().getName());
//                        Log.d("test", "observeOn 接收到的数据:" + "integer:" + integer);
//                    }
//                });

        Flowable.create(new FlowableOnSubscribe<String>() {
            @Override
            public void subscribe(FlowableEmitter<String> e) throws Exception {
                Log.d("test2", "subscribeOn所在的线程：" + Thread.currentThread().getName());
                Log.d("test2", "subscribeOn 发送的数据:" + "1");
                e.onNext("1");
                e.onComplete();
            }
        }, BackpressureStrategy.LATEST)
                .subscribeOn(io.reactivex.schedulers.Schedulers.io())
                .observeOn(io.reactivex.android.schedulers.AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        Log.d("test2", "observeOn 所在的线程：" + Thread.currentThread().getName());
                        Log.d("test2", "observeOn 接收到的数据:" + "s:" + s);
                    }
                });


//        Flowable.just("jj").subscribe(new Consumer<String>() {
//            @Override
//            public void accept(String s) throws Exception {
//                Log.d("test2", "observeOn 所在的线程：" + Thread.currentThread().getName());
//                Log.d("test2", "observeOn 接收到的数据:" + "s:" + s);
//            }
//        });

    }

    private List<Student> getStudents() {
        List<Student> list = new ArrayList<>();
        final Student stu = new Student();
        stu.setAge("20");
        stu.setName("sunsg");
        Course course = new Course("语文", "小李");
        Course course1 = new Course("英语", "小陈");
        List<Course> courses = new ArrayList<>();
        courses.add(course);
        courses.add(course1);
        stu.setCourse(courses);
        list.add(stu);

        final Student stu1 = new Student();
        stu1.setAge("22");
        stu1.setName("sunsg susng");
        Course course2 = new Course("语文2", "小李2");
        Course course3 = new Course("英语2", "小陈2");
        List<Course> courses2 = new ArrayList<>();
        courses2.add(course2);
        courses2.add(course3);
        stu1.setCourse(courses2);

        list.add(stu1);
        return list;
    }
    //=========================================rxjava 2.0=========================================================================

    /**
     * 测试原子变量
     */
    private  void testAtomicboolean(){
        AtomicBoolean ab = new AtomicBoolean(false);

        if(ab.compareAndSet(false,true)){
            Log.i("test11","11111 bbbbbbbbbbbbbbbbbbbbbb = "+ab.get());
        }else{
            Log.i("test11","22222 bbbbbbbbbbbbbbbbbbbbbb = "+ab.get());
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mCompositeDisposablel.dispose();
    }
}
